how to avoid flickering in awt [on hold]
Posted
by
Ishanth
on Game Development
See other posts from Game Development
or by Ishanth
Published on 2013-10-31T13:08:28Z
Indexed on
2013/10/31
16:18 UTC
Read the original article
Hit count: 279
java
import java.awt.event.*;
import java.awt.*;
class circle1 extends Frame implements KeyListener
{
public int a=300;
public int b=70;
public int pacx=360;
public int pacy=270;
public circle1()
{
setTitle("circle");
addKeyListener(this);
repaint();
}
public void paint(Graphics g)
{
g.fillArc (a, b, 60, 60,pacx,pacy);
}
public void keyPressed(KeyEvent e)
{
int key=e.getKeyCode();
System.out.println(key);
if(key==38)
{
b=b-5; //move pacman up
pacx=135;pacy=270; //packman mouth upside
if(b==75&&a>=20||b==75&&a<=945)
{
b=b+5;
}
else
{
repaint();
}
}
else if(key==40)
{
b=b+5; //move pacman downside
pacx=315; pacy=270; //packman mouth down
if(b==645&&a>=20||b==645&&a<=940)
{
b=b-5;
}
else{
repaint();
}
}
else if(key==37)
{
a=a-5; //move pacman leftside
pacx=227; pacy=270; //packman mouth left
if(a==15&&b>=75||a==15&&b<=640)
{
a=a+5;
}
else
{
repaint();
}
}
else if(key==39)
{
a=a+5; //move pacman rightside
pacx=42;pacy=270; //packman mouth right
if(a==945&&a>=80||a==945&&b<=640)
{
a=a-5;
}
else
{
repaint();
}
}
}
public void keyReleased(KeyEvent e){}
public void keyTyped(KeyEvent e){}
public static void main(String args[])
{
circle1 c=new circle1();
c.setVisible(true);
c.setSize(400,400);
}
}
© Game Development or respective owner